package com.example.yangjintingtest.mapper;

import com.example.yangjintingtest.domain.BlogComment;
import com.example.yangjintingtest.domain.Comment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CommentMapper {
    @Select("SELECT * FROM t_comment WHERE id =#{id}")
    public Comment findById(Integer id);
    @Insert("INSERT INTO t_comment(content,author,a_id )" +
            "values (#{content},#{author},#{aId})")
    public int insertComment(Comment comment);
    @Update("UPDATE t_comment SET content=#{content} WHERE id=")
    public int updateComment(Comment comment);
    @Delete("DELETE FROM t_comment WHERE id=#{id}")
    public int deleteComment(Integer id);
// 通过文章id删除评论信息
@Delete("DELETE FROM t_comment WHERE article_id=#{aid}")
public void deleteCommentWithId(Integer aid);

    // 分页展示某个文章的评论
    @Select("SELECT * FROM t_comment WHERE article_id=#{aid} ORDER BY id DESC")
    public List<BlogComment> selectCommentWithPage(Integer aid);

    // 后台查询最新几条评论
    @Select("SELECT * FROM t_comment ORDER BY id DESC")
    public List<BlogComment> selectNewComment();

    // 发表评论
    @Insert("INSERT INTO t_comment (article_id,created,author,ip,content)" +
            "VALUES (#{articleId},#{created},#{author},#{ip},#{content})")
    public void pushComment(BlogComment comment);

    // 站点服务统计，统计评论数量
    @Select("SELECT COUNT(1) FROM t_comment")
    public Integer countComment();
    // 获取评论列表
    @Select ("SELECT t.*, a.title articleTitle FROM t_comment t, t_article a WHERE t.article_id=a.id ORDER BY t.id DESC")
    public List<BlogComment> selectComment();
}
